<?php
    /**
     * Created by PhpStorm.
     * 版权所有: 2019~2022 [ hhygyl ]
     * Date: 2019/8/19-16:27
     * Link: http://luckyadmin.luckyhhy.cn
     * FileName: Bo.php
     * Keys: ctrl+alt+L/ctrl+s(代码格式化) ctrl+J(代码提示) ctrl+R(替换)ALT+INSERT(生成代码(如GET,SET方法,构造函数等) , 光标在类中才生效)
     * CTRL+ALT+O (优化导入的类和包 需要配置) SHIFT+F2(高亮错误或警告快速定位错误)
     * CTRL+SHIFT+Z(代码向前) CTRL+SHIFT+/ (块状注释) ctrl+shift+enter(智能完善代码 如if())
     **************************************************************
     *                                                            *
     *   .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-.       *
     *    |                     ______                     |      *
     *    |                  .-"      "-.                  |      *
     *    |                 /            \                 |      *
     *    |     _          |              |          _     |      *
     *    |    ( \         |,  .-.  .-.  ,|         / )    |      *
     *    |     > "=._     | )(__/  \__)( |     _.=" <     |      *
     *    |    (_/"=._"=._ |/     /\     \| _.="_.="\_)    |      *
     *    |           "=._"(_     ^^     _)"_.="           |      *
     *    |               "=\__|IIIIII|__/="               |      *
     *    |              _.="| \IIIIII/ |"=._              |      *
     *    |    _     _.="_.="\          /"=._"=._     _    |      *
     *    |   ( \_.="_.="     `--------`     "=._"=._/ )   |      *
     *    |    > _.="                            "=._ <    |      *
     *    |   (_/                                    \_)   |      *
     *    |                                                |      *
     *    '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-='      *
     *                                                            *
     *                    JUST FIND YOUR BUG !                    *
     **************************************************************
     */


    namespace app\admin\controller;


    use service\StringService;
    use service\TreeService;
    use think\Exception;
    use think\Validate;

    class Bo extends SystemBase
    {
        protected $admin_bo;
        protected function _initialize()
        {
            parent::_initialize(); // TODO: Change the autogenerated stub
            $this->admin_bo = new \app\admin\model\Bo();//角色模型
        }


        /**
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: index
         * @describe:
         */
        public function index(){
            if($this->request->isAjax()) {
                $param = $this->request->param();//接收参数
                /**
                 * 返回获取的分页数据
                 */
                return $this->admin_bo->GetAdminBoDataPage($param);
            }
            return $this->fetch();
        }



        /**
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: AddBo
         * @describe:轮播图
         */
        public function AddBo(){
            if($this->request->isAjax()){
                $data     = $this->request->post();
                $validate = new Validate([['title|token', 'require', '标题名称不能为空'], ['url', 'url', '填写的url地址错误'],]);
                if(!$validate->check($data)) {
                    $this->error('提交失败：'.$validate->getError());
                }

                $res = $this->admin_bo->addEditData($data); //添加数据
                if($res['code']==1) {
                    if(isset($data['id'])){
                        $this->AddLogs('编辑轮播图【'.$data['title'].'】信息');
                    }else{
                        $this->AddLogs('添加轮播图');
                    }
                    $this->success("操作成功");
                }
                else {
                    $this->error($res['msg']);
                }

            }

            return $this->fetch();
        }



        /**
         * @return mixed
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: EditBo
         * @describe:bianji
         */
        public function EditBo(){
            $id   = $this->request->param("id/d");//父id
            $info = $this->admin_bo->get($id)->toArray();
            $this->assign(compact("info"));
            return $this->fetch();
        }


        /**
         * @author: hhygyl <jackhhy520@qq.com>
         * @name: delete
         * @describe:删除
         */
        public function delete()
        {
            if($this->request->isAjax()) {
                $ids = $this->request->post("ids");
                try {
                    $res = $this->admin_bo->del($ids); //模型删除
                    if($res) {
                        $this->AddLogs('删除轮播图');

                        $this->success("删除成功");
                    }
                    else {
                        $this->error("删除失败");
                    }
                } catch (Exception $exception) {
                    $this->error($exception->getMessage());
                }
            }
        }




    }